package com.sc.admin.service.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.sc.admin.common.util.ObjUtils;
import com.sc.admin.common.util.UserInfoUtils;
import com.sc.admin.model.dto.UserAuthInfo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component    // 保证此类被 SpringBoot 扫描，完成 Sa-Token 的自定义权限验证扩展
public class StpInterfaceImpl implements StpInterface {

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        UserAuthInfo user = UserInfoUtils.getUser();
        if (ObjUtils.isEmpty(user)) return new ArrayList<>();

        return user.getPerms();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        UserAuthInfo user = UserInfoUtils.getUser();
        if (ObjUtils.isEmpty(user)) return new ArrayList<>();

        return user.getRoles();
    }

}
